package com.zt.ztyh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zt.ztyh.dto.LoanDto;
import com.zt.ztyh.dto.LoanUser;
import com.zt.ztyh.entity.User;
import com.zt.ztyh.entity.ZtyhLoanUser;
import com.zt.ztyh.service.ZtyhLoanUserService;
import com.zt.ztyh.mapper.ZtyhLoanUserMapper;
import com.zt.ztyh.vo.loan.LoanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
* @author JIASC
* @description 针对表【ztyh_loan_user】的数据库操作Service实现
* @createDate 2024-04-07 14:13:07
*/
@Service
public class ZtyhLoanUserServiceImpl extends ServiceImpl<ZtyhLoanUserMapper, ZtyhLoanUser>
    implements ZtyhLoanUserService{

    @Autowired
    private ZtyhLoanUserMapper ztyhLoanUserMapper;


    @Override
    public boolean addLoan(LoanUser loanUser) {
        return this.ztyhLoanUserMapper.addLoan(loanUser)>=1;
    }

    @Override
    public Page<LoanVo> findUserLoan(LoanDto loanDto) {
        return this.ztyhLoanUserMapper.findUserLoan(new Page<LoanVo>(loanDto.getPage(),loanDto.getLimit()),loanDto);
    }

    @Override
    public BigDecimal findUserLoanLimit(Long uid) {
        //先查询用户表
        User byUserId = this.ztyhLoanUserMapper.findByUserId(uid);
        int m=0;
        if (byUserId!=null){
            //查询用户额度
            Integer asset = byUserId.getAsset();
            //查询用户信用
            Integer credit = byUserId.getCredit();
            m=asset+credit;
            System.out.println("m==>"+m);
        }
        //根据这个等级取出最高贷款额度
        return this.ztyhLoanUserMapper.findUserByLoanLimit(m);
    }

    @Override
    public LoanUser findById(Long id) {
        return this.ztyhLoanUserMapper.findLoanUserById(id);
    }

    @Override
    public boolean updateLoanById(LoanUser loanUser) {
       return this.ztyhLoanUserMapper.updateLoanById(loanUser)>=1;
    }

    @Override
    public User findUserInfo(Long uid) {
        return this.ztyhLoanUserMapper.findUserInfo(uid);
    }
}




